package cn.ncupyh.soft.opera;

import cn.ncupyh.soft.book.Book;
import cn.ncupyh.soft.book.BookList;

import java.util.Scanner;

/**
 * @version 1.8
 * @Author Djx_hmbb
 * @Date 2023/7/22 10:00
 * @注释:
 */
public class ReturnOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书!");

        System.out.println("请输入你要归还的书名:");
        Scanner s = new Scanner(System.in);
        String name = s.next();
        int currentSize = bookList.getUsedSize();
        //查找是否借过该书
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                if(book.isBorrowed()==false){
                    System.out.println("未借阅过该书!");
                    return;
                }else{
                    book.setBorrowed(false);
                    System.out.println(book);
                    System.out.println("成功归还!");
                    System.out.println(book);
                    return;
                }
            }
        }
        System.out.println("库中没有此书!");
    }
}
